fix npe
Add better logging