Porting fixes from different forks into mainline. Working on build system for 0.8.2