generalized and documented tilemanipulation.lua, updated layerswap.lua