Refactored everything and fixed some silly mistakes. Added a test project.