Preventing some exceptions.

Adding protection against null parameters on some methods.
Also removed some FindBugs warnings.