made compatible with the (obviously much better) solution by robin
may break compatability with your stuff