Fix bug (out-of-range access)