removed unneeded code and unset useless flags