changed functions to simplify use as module