Bit ugly, but works. Happy with it for now, we can always refactor a bit later.