Added null checks and various redundancies.