refactor and make neater