Added check if there are minimum rows

Because less than 3 is trivial
Added constant for minimum rows
Added error messages when running out of memory
Added memory deallocation and removed some output