Converting chunk into 3d texture. Some code cleanup.