cleaned up messy code