Clean up code with Resharper. Fix a few bugs.