Moved most functions into separate source files.