Promises API and some tidying
Merge branch 'deferred-api'