update code to use bigdecimal correctly(ish?), also fix a one bug on the average percent calculation