Rebase and bug fixes