generalised a func, not tested