refactor and structure code in class