Removing duplicate code