refactoring code and adding subscriptions