Fix Github issues 36, 37, 42, 43, 50.