fixing safari bug and simplifying math