converted to using promises, fixes #2