null checks and debug logs