added fopen handling