better organize and refactor