- Changed code to be safe against NullPointerExceptions