Rewrote listener class

added booleans to manage logic better, and made it easier to implement
future changes