Refactoring and optimizations, and trying to clean things up a little.