Basic implementation. Very messy.
Add configurable block sizes other fixes