Refactor of memory allocation, explicit use of bounded checked arrays.