some old code that i wrote, might be useful to others