Messy but it all works