a lot of changes and bug fixes