Yeah this is a bit ugly and should be refactored at some point.