cleanup and bug fixed