implement getPosition algorithm