Second major cleanup of lib/
Merge 61cd5cf1665eda4ae82fcdbcc21ed82fd128eafb into e830fdcaf6417baaa1a01ce0a3b1eff5f945f653
Misc fixes for PR #59