Refactor bonus and penalty calculation (#917)