improved gridToPosition