Some cleanup and bug fixing.