refactor and beautify