Refactor some code to make it easier to make Cairo-less implementations