cleanup and bug fix