some bug fixes and migration to remove old tables