refactor to work when called from another module