Many tweaks and bug fixes