simplified the work flow and some if else condition