Checks layout_location for NULL
Replace terminate call with atexit(terminate)
atexit can take care of cleanup now.