move mathematical operations at better places

Signed-off-by: Sébastien Boisvert <boisvert@anl.gov>