fix, test, and clear up helper functions