refactor and minimalize