Added several null checks