Moved some of the lib functions into separate files