messy code cleanup