Fixed numerous things pointed out by Sean and Horatio