Prevent null pointer exception and fix return character