fixed some bugs, added a function to test for valid coords