refactored tests and fixed two offby O(1) errors