some cleaning and bug fixes