Several changes and bug fixes