Refactor run so it can use tail_call decorator