added flags and if block