Fixing a bug where a NullPointerException would occur