fix pointer alignment with bsearch usage
close a file pointer I forgot about
add function for freeing global memory