Cleans up the code a lot, but need more tests to make sure it didnt bork anything