Cleaned up a lot of code. Hopefully this makes everything easier going forward.