misc cleanup and bug checking