Closes #2, but OH MY GOD so many off-by-one errors avoided