Some possibilities for rewrites of these functions

You should pick the most readable ones.