Fixed issue with flags not resetting properly