cleaned up a lot of clunky code, added messy tags where needs fixing