Fixed bugs. Removed unecessary code