Documentation, code cleanup, unit tests