some cleanup and bug fixing