Added null checks after trying to open file