Cleaned up messy code structure.