Catch possible null pointer
Added comments to code