a bit of cleaning and bug fixes