Fix a bunch of off by one and silly errors