fixed error in formula, renamed and refactored stuff to be more clear