Cleaning and various bugs fixed