nice refactoring by Kevin Wang