Sorted out duplicate code