Changed the code according to @sensej remarks.