adding checks to avoid null pointer exceptions