Tidy up layoutstream (To master instead)

Let's merge this one here, as this fix should go out sooner! 

Refactored the layoutStream to use promises instead of the callback pyramid mess. Also changed the order of rendering: Now the template is processed before the layout. This way data created in the template processing can be available to it's wrapping layout.