extracted calculate method for testing