many more fixes and improvements, tested more code paths.