added wasGhost variable and made unGhost condition set it to true