I guess, really I should generalise this pattern to a fun. Lemme refactor a bit.