refactoring calculations