Moved some functions for better flow