messy, but it works