Added comments, minor fixes, testing code.