Code cleanup
WIP.  Major rewrite of layout methods and base classes.