Reorganized each lib object to its own file.
Code cleanups, function and var name refactoring, add comments.