Implement materialization
Added some (quite lax) unit tests