More Ruby hackery, refactoring, documentation