Fixed out-by-one errors