Fixed some issues and extracted the createBlocks funciton