add some bounds checks