+# Initializing `Model`
 Model ?= {}
 
-Model.BinaryStore =
-	
-	data : []
-	size : [0,0,0]
-	offset : [0,0,0]
-
-	BUCKET_WIDTH : 64
-
-	bucketIndex : (x, y, z) ->
-		(x / @BUCKET_WIDTH - @offset[0] >> 0) + 
-		(y / @BUCKET_WIDTH - @offset[1] >> 0) * @size[0] + 
-		(z / @BUCKET_WIDTH - @offset[2] >> 0) * @size[0] * @size[1]
-	
-	pointIndex : (x, y, z) ->
-		(x % @BUCKET_WIDTH >> 0) +
-		(y % @BUCKET_WIDTH >> 0) * @BUCKET_WIDTH +
-		(z % @BUCKET_WIDTH >> 0) * @BUCKET_WIDTH * @BUCKET_WIDTH
-
-	extendPoints : (x0, y0, z0, x1, y1, z1) ->
-
-		@extendCube(
-			x0 / @BUCKET_WIDTH >> 0,
-			y0 / @BUCKET_WIDTH >> 0,
-			x0 / @BUCKET_WIDTH >> 0,
-			x1 / @BUCKET_WIDTH >> 0,
-			y1 / @BUCKET_WIDTH >> 0,
-			z1 / @BUCKET_WIDTH >> 0
-		)
-
-	extendCube : (x0, y0, z0, x1, y1, z1) ->
-		
-		cubeOffset = [
-			Math.min(x0, x1, @offset[0])
-			Math.min(y0, y1, @offset[1])
-			Math.min(z0, z1, @offset[2])
-		]
-		cubeSize = [
-			Math.max(x0, x1, @offset[0] + @size[0]) - cubeOffset[0] + 1
-			Math.max(y0, y1, @offset[1] + @size[1]) - cubeOffset[1] + 1
-			Math.max(z0, z1, @offset[2] + @size[2]) - cubeOffset[2] + 1
-		]
-
-		cube = []
-		for z in [0...cubeSize[2]]
-			for y in [0...cubeSize[1]]
-				for x in [0...cubeSize[0]]
-					index =
-						(x - @offset[0]) +
-						(y - @offset[1]) * @size[0] +
-						(z - @offset[2]) * @size[0] * @size[1] 
-					
-					cube.push @data[index]
-						
-					
-		@data = cube
-		@offset = cubeOffset
-		@size = cubeSize
-
-	value : (x, y, z, newValue) ->
-
-		bucketIndex = @bucketIndex(x, y, z)
-		bucket = @data[bucketIndex]
-
-		unless newValue?
-			if bucket?
-				bucket[@pointIndex(x, y, z)]
-			else
-				-1
-		else
-			if 0 <= bucketIndex < @data.length
-				unless bucket?
-					bucket = @data[bucketIndex] = new Float32Array(@BUCKET_WIDTH * @BUCKET_WIDTH * @BUCKET_WIDTH)
-					bucket[i] = -1 for i in [0...bucket.length]
-				bucket[@pointIndex(x, y, z)] = newValue
-			else
-				throw "cube fault"
-
+# #Model.Binary#
+# Binary is the real deal.
+# It loads and stores the primary graphical data.
+#
+# **Mixins**: Model.LazyInitializable, Model.Synchronizable
+# 
+# ##Data structure##
+#
+# ###Concept###
+# We store 3-dimensional data with each coordinate >= [0,0,0].
+# Each point is stored in **buckets** which resemble a cubical grid. 
+# Those buckets are kept in an expandable data structure (**cube**) which 
+# represents the smallest cuboid covering all used buckets.
+# 
+# ###Implementation###
+# Each point value (greyscale color) is represented by a number 
+# between 1 and 2, where 1 is black and 2 white. Actually WebGL
+# generally uses [0, 1], but as TypedArrays are initialized with
+# 0 we shift the actual interval to use 0 as an undefined value.
+# 
+# The buckets are implemented as `Float32Array`s with a length of
+# `BUCKET_WIDTH ^ 3`. Each point can be easiliy found through simple 
+# arithmetik (see `Model.Binary.pointIndex`).
+#
+# The cube is defined by the offset `[x,y,z]` and size `[a,b,c]` 
+# of the cuboid. It is actually just a standard javascript array 
+# with each item being either `null` or a bucket. The length of the
+# array is `a * b * c`. Also finding th containing bucket of a point 
+# can be done with pretty simple math (see `Model.Binary.bucketIndex`).
+#
+# ###Inserting###
+# When inserting new data into the data structure we first need
+# to make sure the cube is big enough to cover all points. Otherwise
+# we'll have to expand the cube (see `Model.Binary.expandCube`). 
+# Then we add each point. If the corresponding bucket of a point 
+# isn't initialized we'll handle that on the fly 
+# (see `Model.Binary.value`).
+# 
+#
+# ##Loading##
+# The server provides the coordinates (vertices) and color values of
+# the data separately.
+# 
+# 
+# 
+#         +--+--+--+--+--+--+--+
+#        /  /  /  /  /  /  /  /|
+#       /--/--/--/--/--/--/--/ |
+#      /  /  /  /  /  /  /  /|/|
+#     +--+--+--+--+--+--+--+ | |
+#     |  |  |  |  |  |  |  |/|/|
+#     |--|--|--|--|--|--|--| | |
+#     |  |  |  |  |  |  |  |/|/
+#     |--|--|--|--|--|--|--| /
+#     |  |  |  |  |  |  |  |/
+#     +--+--+--+--+--+--+--+
+#
+#
+
+#
 Model.Binary =
-
+	
 	vertexTemplate : null
 	
 	initialize : (callback) ->

			return false


_.extend Model.Binary, Model.BinaryStore
_.extend Model.Binary, Model.Synchronizable
_.extend Model.Binary, Model.LazyInitializable
_.extend Model.Mesh, Model.Cacheable


			@load position, direction, @synchronizingCallback(loadedData, finalCallback)

	load : (position, direction, callback) ->
		@lazyInitialize (err) ->
			return callback(err) if err

			request
				url : "/binary/data/cube?px=#{position[0]}&py=#{position[1]}&pz=#{position[2]}&ax=#{direction[0]}&ay=#{direction[1]}&az=#{direction[2]}"
				responseType : 'arraybuffer'
				,
				(err, data) ->
