chkmem() improved to handle chunks and functions separately