added fopen and modified main