fixed bug in isValidPos