Cleaned up main layout code.