corrected the formula and cleaned up a bit