Added libraries and lots of refactoring to allow for better code