Fixed an NPE I've been trying to fix for ages