Moved helper functions to the bottom