refactor to reduce number of scripts