Add commandline parsing, debug mode, and refactor so things make more sense