Cleaned up and fixed off-by-ones