Fixing bugs and code cleanup.