finally figured out the math portion