Added unsubscribing, disconnecting, some code optimizations