Code cleanup. Minimal changes to the main code.