Added object-assign and replacestream deps
Refactored middleware
Fixed client code