refactored, made manager global, added event listening and callback