changed order of operations
Merge pull request #867 from cloudnull/Issue866

changed order of operations