Refactor -flatten: to fix crash and use RACCompoundDisposable

Fixes #711.