Some physics code refactoring