redesigned the while loop in compress