Refactoring + logging refining + exception reduction
If we can prevent a NPE by using a != null check earlier, we'll avoid
generating a NPE object in the event that the object is null.