cleaning up duplicate code