another rewrite - still not finished