Cleaned up and refactored. Ready for further processing.