[READY] clean up by cordoval

Sent with [Gush](http://github.com/gushphp/gush)

**Description**: This is a big push towards refactoring it into a sharable component that could migrate into a Gush adapter.