Improvements and bug fixes