works, but pretty messy still