Moved functions and types to files to better denote what they relate to