Fixed get_mem_layout to correctly return the right number of chunks