Cleaned up and refactored.