fixed some duplicate code