refactor mess