avoiding NPE and other exceptions