Cleaning up messy code