first pass at refactorying