Moved code into libraries