Cleaned up dead code and refactored.