Gateway recovery

This PR can be checked in after the demo is over. I don't think there is any rush to commit it in right now.

@stonier: This might require a thorough code review