add deferreds, minor refactor