code modified to work in my case (normal case won't work)