code cleanup
add null checks