code refactor and better naming for functions