Tweaked some functions and moved them to main.functions where they belong