This whole block needs more documentation inside.