Make layout a class and document it. Minor bug fixes.