Code cleanup.
Bug fixes