Use promises and scopes more

This should finally fix #14.