Removing unnecessary code from listener