Split calculate function into two functions