Error checking & Clean-up

Fixed a bug with 0 sized or negative integer maps causing segmentation faults, added error checking to mallocs, map sizes and (sanitized?) the free_level() function.