cleanup & update flags