updated to remove duplicate code