First version, still needs a lot of cleanup and refactoring
First working version