Cleaning and Adding Error checking