moved files from routes to lib. Fixed small error with building streams.