some minor code changes

-catch/prevent some NPE and other errors