Added null checks and various redundancies.

Merge dev to master.