Fix for index out of bounds exception