Refactor task/result handling (WIP)