this part would be a lot nicer if we did something like `toCallback(result)` below, lots of nested conditionals are really confusing to read