Refactor some methods and remove useless variables and space