Moved some functions out