Move helper functions to own file