corrected -1 offset bug