Cleaned up the code.

This should address the rest of #335.