merged almost all, some changes pending