simplify code a bit and move generic helpers to separate file
clean up todo