modified the code for smooth app flow