move functions to helper file; refine hash function