some minor changes, still not tested