ported some old code