Added lots of operations, removed unneeded functions, tidied code