Refactor retry_shanbay
split main function