refactored everything into a constructor