moved helper functions to lib/