Added the flatten and unflatten LSP functions