updated code in multiple functions. added variables. added math.