made the functionality more generic

you can add a callback to be called when the state changes