diff --git a/Irpg/Quest.pm b/Irpg/Quest.pm
index 74e7f46e6959219701426f737af74eaef694105e..9740f747a9ae74fc09c6e352770d36cfdd4ed65c 100644
--- a/Irpg/Quest.pm
+++ b/Irpg/Quest.pm
@@ -21,12 +21,39 @@ my $opts;
 my $rps;
 =head1 FUNCTION init_hashes
     This function sets the references to
-    options and players hashes.
+    options and players hashes, and init quest if 
 =over
 =item SCALAR (ref)    - reference to the options hash
 =item SCALAR (ref)    - reference to the players hash
 =cut
-sub init_pkg { ($opts, $rps) = @_; }
+sub init_pkg { ($opts, $rps) = @_; readquestfile();}
+
+=head FUNCTION readquestfile
+    This function reads a quest state from the file
+    and set it.
+=cut
+sub readquestfile {
+    return unless $opts->{writequestfile};
+    open(QF,"<$opts->{questfilename}") or do {
+        Irpg::Irc::chanmsg("Error: Cannot open $opts->{questfilename}: $!");
+        return;
+    };
+    while ( <QF> ) {
+        chomp;
+        $quest{text}  = substr($_, 2) if (m/^T /);
+        $quest{type}  = substr($_, 2) if (m/^Y /);
+        $quest{qtime} = substr($_, 2) if (m/^S / && $quest{type} == 1);
+        $quest{stage} = substr($_, 2) if (m/^S / && $quest{type} == 2);
+        (
+            $quest{p1}->[0],
+            $quest{p1}->[1],
+            $quest{p2}->[0],
+            $quest{p2}->[1],
+        ) = m/(\d+) (\d+) (\d+) (\d+)/ if (m/^P /);
+        push(@{$quest{questers}}, $1) if (m/^P\d (\w+)/);
+    }
+    close(QF);
+}
 
 =head FUNCTION writequestfile
     This function write the state of the current quest
@@ -193,30 +220,22 @@ sub movequesters {
         writequestfile();
     }
     else {
-        my %positions = ();
+        my $phase = 'p'.(int($quest{stage} == 2) + 1);
         for (@{$quest{questers}}) {
-            if ($quest{stage} == 1) {
-                if (rand(100) < 1) {
-                    if ($rps->{$_}{x} != $quest{p1}->[0]) {
-                        $rps->{$_}{x} += ($rps->{$_}{x} < $quest{p1}->[0] ?
-                                        1 : -1);
-                    }
-                    if ($rps->{$_}{y} != $quest{p1}->[1]) {
-                        $rps->{$_}{y} += ($rps->{$_}{y} < $quest{p1}->[1] ?
-                                        1 : -1);
-                    }
+            if (rand(100) < 1) {
+                if ($rps->{$_}{x} != $quest{$phase}->[0]) {
+                    $rps->{$_}{x} +=
+                        (($quest{$phase}->[0] - $rps->{$_}{x}) % $opts->{mapx} <
+                         ($rps->{$_}{x} - $quest{$phase}->[0]) % $opts->{mapx} ?
+                            1 : -1);
+                    $rps->{$_}{x} %= $opts->{mapx};
                 }
-            }
-            elsif ($quest{stage}==2) {
-                if (rand(100) < 1) {
-                    if ($rps->{$_}{x} != $quest{p2}->[0]) {
-                        $rps->{$_}{x} += ($rps->{$_}{x} < $quest{p2}->[0] ?
-                                        1 : -1);
-                    }
-                    if ($rps->{$_}{y} != $quest{p2}->[1]) {
-                        $rps->{$_}{y} += ($rps->{$_}{y} < $quest{p2}->[1] ?
-                                        1 : -1);
-                    }
+                if ($rps->{$_}{y} != $quest{$phase}->[1]) {
+                    $rps->{$_}{y} +=
+                        (($quest{$phase}->[1] - $rps->{$_}{y}) % $opts->{mapy} <
+                         ($rps->{$_}{y} - $quest{$phase}->[1]) % $opts->{mapy} ?
+                            1 : -1);
+                    $rps->{$_}{y} %= $opts->{mapy};
                 }
             }
         }