Refactored

I think, global var's are not necessery here.