refactor and formatting