added if-statement for grexists