fixed some NULL pointer issues and workaround for mem_usage