catch NumberFormatException, fixed off-by-one error