Add boundry checking.
Merge pull request #1 from martamccasland/master

Added boundary checking.