first 'real' script using functions, but don't like it quite yet. Need to handle rounding better