messy but it's working