Updated version

I've updated your code a bit. 
Sergey Ronin, Stackoverflow