some cleanup and add necessary flag