Added 'on connected' callback and started reorganizing connection flow