Code cleanup and bugs.