refactor to minify code