bug fixes and removed un-needed code