cleanup and bug fix.