implemented jeremy's solution