Fixes NPE in some cases