Bug fixes and impovements