Added a few code optimizations and fixed a bug where beforeSubscribe was being called before unsubscriptions.