improvements and bug correction