Moved helper functions to separate file (cleaning up a bit)