Messy but it works