Added event handleing logic