Added code to prevent NPE in newly refactored method

Code review : Chezka Arevalo