Code cleaning and bug fixes.