Refactoring library; major cleanup progress