Fixed calculation by dividing percentages by 100

+ some error checking