Added additional bound checks.