test updates to handle more possible npes by refactoring into a more scala-ish way