pulled calculation out into separate function