make Deferreds thenable and refactor core