implemented validPosition check