LAYER: check for NULL pointers and do basic checks.

Signed-off-by: bert <bert.timmerman@xs4all.nl>
LAYER: according to R13 and R14.

Signed-off-by: bert <bert.timmerman@xs4all.nl>