Added return with error code if file open fails