fixed division algorithm
fixed minor bugs