Fixed Null Pointer Exception.

Finalized code by fixing null pointer exception, leading to proper returns.