Added comments and an optimization in unlock()