add guarding code to avoid NullPointerException in #139