Really messy but works