added a try/except block to handle empty contents