Added config/cleaned up code/fixed bugs

Added user configurable config, made the code easier to read, and fixed
minor bugs