I think there are off by one errors in a lot of places. Will go through
code line-by-line when it's not 4:45 AM.