Refactor: Calclulations into function.