Fixed logic a little. I was testing it in virtual environment, so missed this part.
Hope now everything will work well