fixed error in relation to boundary checking