removing duplicate code