Layout adjust and null ptr bug fixes