Clean up and flag implementation