Removed unnecesary code and fixed some bugs