Fixes several NPEs