clean up the way events are handled and use std::function