refactor and better formatting