optimization for fortran, removed a lot of unnecessary ifs and dos