Moved calc into its own function