Move helper functions to separate file