moved computation into its own function