Simple boundary checking added