refactor to run correctly