Simplified the latching function