a bit of cleaning and bug fixing