cleaned up after everybody. Refactored and tweaked. Feel free to dispute changes