Removed duplication for ifNotNull checks. Added generic method for this. Should probably switch to apache commons now that I think about it.