Substitiuted sub with routine and removed redundant code