Code cleanup. All tests now pass.