consolidate functions, clean a bit