cleaned up duplicate code