many changes and bug fixes