applied Lari's fixes from the hibernate plugin