not pretty, but works