Added comments to code and removed some unused functions