refactor and better flash