refactor position formula