Added jquery stuff to auto calculate figures and a bunch of clean ups