improve arrays and refactor each logic