Cleaned up some messy code