More fixes and some already pulled

Since you pulled some of fixes before, there are some conflicts. If you sync up our forks, I can send other fixes we may implement directly and we'll avoid conflicts.