Code cleanup

This makes some minor modifications to make the code easier to read and test.