some improvements and bug fixes.