all the heavy math is in. Have to prettify and clarify now