Fixing outofbounds error