lab 2 refactor, eliminating 2 instanceof