Clean up ugliness in lib.py