Off by one error and superflous debug output