Restructured code and removed unneccessary functions