Bug fixes. Code cleanup.