Fairly large refactoring. Lots of stuff renamed for the sake of clarity