loosely based on haphash by David Leadbeater