Added null character error check and removed unnecessary try/except
block.