implemented Z-ordering