Bug fixes and removing extra code