Modified the code for checkPos method.