diff --git a/Irpg/Admin.pm b/Irpg/Admin.pm
index a3d2b8067240b184d3412787362e34ac40b49957..f12b8e796d00aa3664bb3ea9fb7cb8c9135fff57 100644
--- a/Irpg/Admin.pm
+++ b/Irpg/Admin.pm
@@ -3,8 +3,8 @@ package Irpg::Admin;
 use strict;
 use warnings;
 use Irpg::Utils qw(:data :text);
-use Irpg::Irc qw(:interaction $sock, @queue);
-use IRPG::Events qw(hog);
+use Irpg::Irc qw(:interaction $sock @queue);
+use Irpg::Event qw(hog);
 
 
 my $opts;
@@ -19,13 +19,13 @@ my $rps;
 sub init_hashes { ($opts, $rps) = @_; }
 
 sub join_chans {
-	for (@_[3..$#arg]) {
+	for (@_[3..$#_]) {
 		sts("JOIN $_");
 	}
 }
 
 sub leave_chans {
-	for (@_[3..$#arg]) {
+	for (@_[3..$#_]) {
 		sts("PART $_");
 	}
 }
@@ -57,8 +57,8 @@ sub delold {
 	else {
 		my @oldaccounts = grep { (time()-$rps->{$_}{lastlogin}) >
 								 ($arg[0] * 86400) &&
-								 !$rps->{$_}{online} } keys(%rps);
-		delete(@rps->{@oldaccounts});
+								 !$rps->{$_}{online} } keys(%$rps);
+		delete(@$rps->{@oldaccounts});
 		chanmsg(scalar(@oldaccounts)." accounts not accessed in ".
 				"the last $arg[0] days removed by $usernick.");
 	}
@@ -97,7 +97,7 @@ sub mkadmin {
 
 sub rmadmin {
 	my ($usernick, $username, $source, @arg) = @_;
-	if ($opts{ownerdelonly} && $opts{owner} ne $username) {
+	if ($opts->{ownerdelonly} && $opts->{owner} ne $username) {
 		privmsg("You don't have access to RMADMIN.", $usernick);
 	}
 	elsif (!defined($arg[0])) {
@@ -106,7 +106,7 @@ sub rmadmin {
 	elsif (!exists($rps->{$arg[0]})) {
 		privmsg("No such account $arg[0].", $usernick, 1);
 	}
-	elsif ($arg[0] eq $opts{owner}) {
+	elsif ($arg[0] eq $opts->{owner}) {
 		privmsg("Cannot RMADMIN owner account.", $usernick, 1);
 	}
 	else {
@@ -143,7 +143,7 @@ sub chpass {
 	}
 }
 
-sub chpass {
+sub chuser {
 	my ($usernick, $username, $source, @arg) = @_;
 	if (!defined($arg[1])) {
 		privmsg("Try: CHUSER <char name> <new char name>",
@@ -199,7 +199,7 @@ sub restart {
 	my ($usernick, $username, $source, @arg) = @_;
 	writedb();
 	sts("QUIT :RESTART from $usernick",1);
-	close($sock);
+	close($Irpg::Irc::sock);
 	exec("perl $0");
 }
 
@@ -212,7 +212,7 @@ sub do_backup {
 
 sub clearq {
 	my ($usernick, $username, $source, @arg) = @_;
-	undef(@queue);
+	undef(@Irpg::Irc::queue);
 	chanmsg("Outgoing message queue cleared by $usernick.");
 	privmsg("Outgoing message queue cleared.",$usernick,1);
 }
@@ -234,6 +234,6 @@ our $commands = {
 	restart => {ref => \&restart,	 adm => 1, prv => 1, pub => 0},
 	backup	=> {ref => \&do_backup,	 adm => 1, prv => 1, pub => 0},
 	clearq	=> {ref => \&clearq,	 adm => 1, prv => 1, pub => 0}
-}
+};
 
 1;
diff --git a/Irpg/Event.pm b/Irpg/Event.pm
index c8055567a4d57d31e05d44eda56483a885e2a75f..6546ce040ebab42f7d92027bba6e24bfde363246 100644
--- a/Irpg/Event.pm
+++ b/Irpg/Event.pm
@@ -347,6 +347,7 @@ sub goodness {
 
 sub rpcheck {
 	my $rpreport = shift;
+	my $online = shift;
     my $onlineevil = scalar(grep { $rps->{$_}{online} &&
                                    $rps->{$_}{alignment} eq "e" } keys(%$rps));
     my $onlinegood = scalar(grep { $rps->{$_}{online} &&
diff --git a/Irpg/Example.pm b/Irpg/Example.pm
index 006e27997a80f7e462e66c4f5e5624f8d961f268..41bce3e334793a011f2c1fadbd193a1b5bcec421 100644
--- a/Irpg/Example.pm
+++ b/Irpg/Example.pm
@@ -44,6 +44,6 @@ our $commands = {
 		prv => 0,
 		pub => 1
 	}
-}
+};
 
 1;
diff --git a/Irpg/Fight.pm b/Irpg/Fight.pm
index 86d298d8d41fccda9adc8bda75e9f057ceccf1cd..4bfdf7939d7716626e3de9c1f565f330f3de49c3 100644
--- a/Irpg/Fight.pm
+++ b/Irpg/Fight.pm
@@ -8,6 +8,7 @@ use Exporter qw(import);
 our @EXPORT = qw(&challenge_opp &collision_fight &team_battle);
 our @EXPORT_OK = qw(itemsum);
 
+my $primnick_ref;
 my $opts;
 my $rps;
 =head1 FUNCTION init_hashes
@@ -17,7 +18,7 @@ my $rps;
 =item SCALAR (ref)	- reference to the options hash
 =item SCALAR (ref)	- reference to the players hash
 =cut
-sub init_hashes { ($opts, $rps) = @_; }
+sub init_hashes { ($opts, $rps, $primnick_ref) = @_; }
 
 
 sub fisher_yates_shuffle {
@@ -37,8 +38,8 @@ sub itemsum {
     my $battle = shift;
     return -1 unless defined $user;
     my $sum = 0;
-    if ($user eq $primnick) {
-        for my $u (keys(%rps)) {
+    if ($user eq $$primnick_ref) {
+        for my $u (keys(%$rps)) {
             $sum = itemsum($u) if $sum < itemsum($u);
         }
         return $sum+1;
@@ -56,16 +57,16 @@ sub itemsum {
 sub challenge_opp { # pit argument player against random player
     my $u = shift;
     if ($rps->{$u}{level} < 25) { return unless rand(4) < 1; }
-    my @opps = grep { $rps->{$_}{online} && $u ne $_ } keys(%rps);
+    my @opps = grep { $rps->{$_}{online} && $u ne $_ } keys(%$rps);
     return unless @opps;
     my $opp = $opps[int(rand(@opps))];
-    $opp = $primnick if rand(@opps+1) < 1;
+    $opp = $$primnick_ref if rand(@opps+1) < 1;
     my $mysum = itemsum($u,1);
     my $oppsum = itemsum($opp,1);
     my $myroll = int(rand($mysum));
     my $opproll = int(rand($oppsum));
     if ($myroll >= $opproll) {
-        my $gain = ($opp eq $primnick)?20:int($rps->{$opp}{level}/4);
+        my $gain = ($opp eq $$primnick_ref)?20:int($rps->{$opp}{level}/4);
         $gain = 7 if $gain < 7;
         $gain = int(($gain/100)*$rps->{$u}{next});
         chanmsg(clog("$u [$myroll/$mysum] has challenged $opp [$opproll/".
@@ -76,7 +77,7 @@ sub challenge_opp { # pit argument player against random player
         my $csfactor = $rps->{$u}{alignment} eq "g" ? 50 :
                        $rps->{$u}{alignment} eq "e" ? 20 :
                        35;
-        if (rand($csfactor) < 1 && $opp ne $primnick) {
+        if (rand($csfactor) < 1 && $opp ne $$primnick_ref) {
             $gain = int(((5 + int(rand(20)))/100) * $rps->{$opp}{next});
             chanmsg(clog("$u has dealt $opp a Critical Strike! ".
                          duration($gain)." is added to $opp\'s clock."));
@@ -84,7 +85,7 @@ sub challenge_opp { # pit argument player against random player
             chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}).
                     ".");
         }
-        elsif (rand(25) < 1 && $opp ne $primnick && $rps->{$u}{level} > 19) {
+        elsif (rand(25) < 1 && $opp ne $$primnick_ref && $rps->{$u}{level} > 19) {
             my @items = ("ring","amulet","charm","weapon","helm","tunic",
                          "pair of gloves","set of leggings","shield",
                          "pair of boots");
@@ -101,7 +102,7 @@ sub challenge_opp { # pit argument player against random player
         }
     }
     else {
-        my $gain = ($opp eq $primnick)?10:int($rps->{$opp}{level}/7);
+        my $gain = ($opp eq $$primnick_ref)?10:int($rps->{$opp}{level}/7);
         $gain = 7 if $gain < 7;
         $gain = int(($gain/100)*$rps->{$u}{next});
         chanmsg(clog("$u [$myroll/$mysum] has challenged $opp [$opproll/".
@@ -128,7 +129,7 @@ sub collision_fight {
                      "removed from $u\'s clock."));
         $rps->{$u}{next} -= $gain;
         chanmsg("$u reaches next level in ".duration($rps->{$u}{next}).".");
-        if (rand(35) < 1 && $opp ne $primnick) {
+        if (rand(35) < 1 && $opp ne $$primnick_ref) {
             $gain = int(((5 + int(rand(20)))/100) * $rps->{$opp}{next});
             chanmsg(clog("$u has dealt $opp a Critical Strike! ".
                          duration($gain)." is added to $opp\'s clock."));
@@ -136,7 +137,7 @@ sub collision_fight {
             chanmsg("$opp reaches next level in ".duration($rps->{$opp}{next}).
                     ".");
         }
-        elsif (rand(25) < 1 && $opp ne $primnick && $rps->{$u}{level} > 19) {
+        elsif (rand(25) < 1 && $opp ne $$primnick_ref && $rps->{$u}{level} > 19) {
             my @items = ("ring","amulet","charm","weapon","helm","tunic",
                          "pair of gloves","set of leggings","shield",
                          "pair of boots");
@@ -153,7 +154,7 @@ sub collision_fight {
         }
     }
     else {
-        my $gain = ($opp eq $primnick)?10:int($rps->{$opp}{level}/7);
+        my $gain = ($opp eq $$primnick_ref)?10:int($rps->{$opp}{level}/7);
         $gain = 7 if $gain < 7;
         $gain = int(($gain/100)*$rps->{$u}{next});
         chanmsg(clog("$u [$myroll/$mysum] has come upon $opp [$opproll/$oppsum".
@@ -165,15 +166,15 @@ sub collision_fight {
 }
 
 sub team_battle { # pit three players against three other players
-    my @opp = grep { $rps{$_}{online} } keys(%rps);
+    my @opp = grep { $rps->{$_}{online} } keys(%$rps);
     return if @opp < 6;
     splice(@opp,int(rand(@opp)),1) while @opp > 6;
     fisher_yates_shuffle(\@opp);
     my $mysum = itemsum($opp[0],1) + itemsum($opp[1],1) + itemsum($opp[2],1);
     my $oppsum = itemsum($opp[3],1) + itemsum($opp[4],1) + itemsum($opp[5],1);
-    my $gain = $rps{$opp[0]}{next};
+    my $gain = $rps->{$opp[0]}{next};
     for my $p (1,2) {
-        $gain = $rps{$opp[$p]}{next} if $gain > $rps{$opp[$p]}{next};
+        $gain = $rps->{$opp[$p]}{next} if $gain > $rps->{$opp[$p]}{next};
     }
     $gain = int($gain*.20);
     my $myroll = int(rand($mysum));
@@ -183,18 +184,18 @@ sub team_battle { # pit three players against three other players
                      "team battled $opp[3], $opp[4], and $opp[5] [$opproll/".
                      "$oppsum] and won! ".duration($gain)." is removed from ".
                      "their clocks."));
-        $rps{$opp[0]}{next} -= $gain;
-        $rps{$opp[1]}{next} -= $gain;
-        $rps{$opp[2]}{next} -= $gain;
+        $rps->{$opp[0]}{next} -= $gain;
+        $rps->{$opp[1]}{next} -= $gain;
+        $rps->{$opp[2]}{next} -= $gain;
     }
     else {
         chanmsg(clog("$opp[0], $opp[1], and $opp[2] [$myroll/$mysum] have ".
                      "team battled $opp[3], $opp[4], and $opp[5] [$opproll/".
                      "$oppsum] and lost! ".duration($gain)." is added to ".
                      "their clocks."));
-        $rps{$opp[0]}{next} += $gain;
-        $rps{$opp[1]}{next} += $gain;
-        $rps{$opp[2]}{next} += $gain;
+        $rps->{$opp[0]}{next} += $gain;
+        $rps->{$opp[1]}{next} += $gain;
+        $rps->{$opp[2]}{next} += $gain;
     }
 }
 
diff --git a/Irpg/Irc.pm b/Irpg/Irc.pm
index 795372cfc9680b91c2a90f1c67db78690cca7fdf..b992f4dd378326db8e1bda15d6f022cf5cd58838 100644
--- a/Irpg/Irc.pm
+++ b/Irpg/Irc.pm
@@ -22,9 +22,12 @@ use IO::Select;
 use Irpg::Utils;
 use Irpg::Main qw($silentmode);
 use Exporter qw(import);
-our @EXPORT_OK = qw($sock @queue &irc_connect &irc_clean &checkmsg &fq &sts &privmsg &chanmsg &notice $inbytes);
+our @EXPORT_OK = qw($sock @queue
+					&irc_connect &irc_clean
+					&checkmsg &fq &sts
+					&privmsg &chanmsg &notice $inbytes);
 our %EXPORT_TAGS = (connection=>[qw($sock &irc_connect &irc_clean &checkmsg &fq)],
-					interaction=>[qw(&sts &privmsg &chanmsg &notice, $)]);
+					interaction=>[qw(&sts &privmsg &chanmsg &notice)]);
 
 
 my $outbytes = 0; # sent bytes
diff --git a/Irpg/Main.pm b/Irpg/Main.pm
index c7e7dab9a8f650d5f62bab5c5b3828b04e2f405e..37eb0ec304913d69ea70fecfde603d0fbb8d4b43 100644
--- a/Irpg/Main.pm
+++ b/Irpg/Main.pm
@@ -28,12 +28,38 @@ my %commands; # filling at the very bottom
 my $rpreport = 0; # constant for reporting top players
 my $lastreg = 0; # holds the time of the last reg. cleared every second.
                  # prevents more than one account being registered / second
-my $lasttime = 1; # last time that rpcheck() was run
+my $lasttime_ref;
 my %split; # holds nick!user@hosts for clients that have been netsplit
 my %onchan; # users on game channel
 
 my $pausemode = 0; # pausemode on/off flag
 my $silentmode = 0; # silent mode 0/1/2/3, see head of file
+
+my $primnick;
+my $opts;
+my $rps;
+my $prev_online;
+my $auto_login;
+=head1 FUNCTION init_pkg
+	This function sets the references to
+	options and players hashes.
+=over
+=item SCALAR (ref)	- reference to the options hash
+=item SCALAR (ref)	- reference to the players hash
+=item SCALAR (ref)	- reference to the prev_online hash
+=item SCALAR (ref)	- reference to the auto_login hash
+=cut
+sub init_pkg {
+	($opts, $rps, $lasttime_ref, $prev_online, $auto_login) = @_;
+	$primnick = $opts->{botnick}; # for regain or register checks
+	Irpg::Quest::init_pkg($opts, $rps);
+	Irpg::Fight::init_pkg($opts, $rps, \$primnick);
+	Irpg::Event::init_pkg($opts, $rps);
+	Irpg::Admin::init_pkg($opts, $rps);
+	Irpg::Users::init_pkg($opts, $rps, \%onchan, \$primnick,
+						  \$lastreg, \$silentmode, \$pausemode);
+}
+
 sub pause_mode {
 	my ($usernick, $username, $source, @arg) = @_;
 	$pausemode = $pausemode ? 0 : 1;
@@ -53,7 +79,7 @@ sub silent_mode {
 
 sub reloaddb {
 	my ($usernick, $username, $source, @arg) = @_;
-	elsif (!$pausemode) {
+	if (!$pausemode) {
 		privmsg("ERROR: Can only use LOADDB while in PAUSE mode.",
 				$usernick, 1);
 	}
@@ -65,30 +91,6 @@ sub reloaddb {
 }
 
 
-my $primnick;
-my $opts;
-my $rps;
-my $prev_online;
-my $auto_login;
-=head1 FUNCTION init_hashes
-	This function sets the references to
-	options and players hashes.
-=over
-=item SCALAR (ref)	- reference to the options hash
-=item SCALAR (ref)	- reference to the players hash
-=item SCALAR (ref)	- reference to the prev_online hash
-=item SCALAR (ref)	- reference to the auto_login hash
-=cut
-sub init_hashes {
-	($opts, $rps, $prev_online, $auto_login) = @_;
-	$primnick = $opts->{botnick}; # for regain or register checks
-	Irpg::Quest::init_hashes($opts, $rps);
-	Irpg::Fight::init_hashes($opts, $rps);
-	Irpg::Event::init_hashes($opts, $rps);
-	Irpg::Admin::init_hashes($opts, $rps);
-	Irpg::Users::init_hashes($opts, $rps);
-}
-
 
 =head1 FUNCTION finduser
 	This function returns the online user associated to a nick.
@@ -163,7 +165,7 @@ sub penalize {
     elsif ($type eq "part") {
         $pen = int(200 * ($opts->{rppenstep}**$rps->{$username}{level}));
         $rps->{$username}{online}=0;
-		$reason = 'parting'
+		$reason = 'parting';
         $pen_key = 'pen_part';
     }
     elsif ($type eq "kick") {
@@ -181,7 +183,7 @@ sub penalize {
 		$pen = $opts->{limitpen};
 	}
 	$rps->{$username}{$pen_key} += $pen if (exists($rps->{$username}{$pen_key}));
-    $rps->{$username}{next} += $pen 
+    $rps->{$username}{next} += $pen;
 	if (defined($reason)) {
         notice("Penalty of ".duration($pen)." added to your timer for ".
                "$reason.",$rps->{$username}{nick});
@@ -191,7 +193,7 @@ sub penalize {
 }
 
 sub moveplayers {
-    return unless $lasttime > 1;
+    return unless $$lasttime_ref > 1;
     my $onlinecount = grep { $rps->{$_}{online} } keys %$rps;
     return unless $onlinecount;
     for (my $i=0;$i<$rps->{self_clock};++$i) { # this is to simulate 1 move/s
@@ -250,9 +252,9 @@ sub rpcheck { # check levels, update database
 	### ALL MODULES CHEKS ###
     # statements using $rpreport do not bother with scaling by the clock because
     # $rpreport is adjusted by the number of seconds since last rpcheck()
-	Irpg::Quest::rpcheck($rpreport); ### QUEST BUSINESS ###
-	Irpg::Fight::rpcheck($rpreport); ### FIGHT BUSINESS ###
-	Irpg::Event::rpcheck($rpreport); ### EVENT BUSINESS ###
+	Irpg::Quest::rpcheck($rpreport, $online); ### QUEST BUSINESS ###
+	Irpg::Fight::rpcheck($rpreport, $online); ### FIGHT BUSINESS ###
+	Irpg::Event::rpcheck($rpreport, $online); ### EVENT BUSINESS ###
 
 	### TOP PLAYERS REPORT ###
     if ($rpreport && $rpreport%36000==0) { # 10 hours
@@ -289,13 +291,13 @@ sub rpcheck { # check levels, update database
     # successful join to $opts->{botchan}, initial value is 1). if fails to open
     # $opts->{dbfile}, will not update $lasttime and so should have correct values
     # on next rpcheck(). 
-    if ($lasttime != 1) {
+    if ($$lasttime_ref != 1) {
         my $curtime=time();
         for my $k (keys(%$rps)) {
             if ($rps->{$k}{online} && exists $rps->{$k}{nick} &&
                 $rps->{$k}{nick} && exists $onchan{$rps->{$k}{nick}}) {
-                $rps->{$k}{next} -= ($curtime - $lasttime);
-                $rps->{$k}{idled} += ($curtime - $lasttime);
+                $rps->{$k}{next} -= ($curtime - $$lasttime_ref);
+                $rps->{$k}{idled} += ($curtime - $$lasttime_ref);
                 if ($rps->{$k}{next} < 1) {
                     $rps->{$k}{level}++;
                     if ($rps->{$k}{level} > 60) {
@@ -319,7 +321,7 @@ sub rpcheck { # check levels, update database
         }
         if (!$pausemode && $rpreport%60==0) { writedb($opts, $rps); }
         $rpreport += $opts->{self_clock};
-        $lasttime = $curtime;
+        $$lasttime_ref = $curtime;
     }
 }
 
@@ -333,7 +335,7 @@ sub rpcheck { # check levels, update database
 =cut
 sub parse {
     my($in) = shift;
-    $inbytes += length($in); # increase parsed byte count
+    $Irpg::Irc::inbytes += length($in); # increase parsed byte count
     $in =~ s/[\r\n]//g; # strip all \r and \n
     debug("<- $in");
     my @arg = split(/\s/,$in); # split into "words"
@@ -365,7 +367,7 @@ sub parse {
             sts("WHO $opts->{botchan}");
             (my $opcmd = $opts->{botopcmd}) =~ s/%botnick%/$opts->{botnick}/eg;
             sts($opcmd);
-            $lasttime = time(); # start rpcheck()
+            $$lasttime_ref = time(); # start rpcheck()
         }
     }
     elsif ($arg[1] eq 'quit') {
@@ -471,7 +473,7 @@ sub parse {
 
 		# if the first word of the msg is "botnick:", 
 		# we interpret the following as a potential command
-		if (@arg[3] eq lc($opts->{botnick}).':') {
+		if ($arg[3] eq lc($opts->{botnick}).':') {
 			@arg = (@arg[0..2], $opts->{token}.$arg[4], @arg[5..$#arg])
 		}
 		my $msgtype = '';
@@ -486,7 +488,7 @@ sub parse {
 
         }
 		if (grep /^\Q$opts->{token}\E$pref\Q$arg[3]\E/, 
-				 @{grep { $_{$msgtype} } keys(%commands)}) {
+				 @{grep({ $_{$msgtype} } keys(%commands))}) {
 			# the message is a command valid in $msgtype message
 			if (!$commands{$arg[3]}->{adm} || ha($usernick)) {
 				# the user has right to execute the command
@@ -498,7 +500,7 @@ sub parse {
 					$commands{$arg[3]}->{ref}($usernick, $username,
 											  $arg[2], @arg[4..$#arg]);
 				} else {
-					notice("Sorry, you're not in $opts{botchan}.",
+					notice("Sorry, you're not in $opts->{botchan}.",
 							$usernick);
 				}
 			} else {
@@ -511,15 +513,17 @@ sub parse {
     }
 }
 
+my ($k, $v);
+while (($k,$v) = each %$Irpg::Quest::commands) {$commands{$k} = $v;}
+while (($k,$v) = each %$Irpg::Fight::commands) {$commands{$k} = $v;}
+while (($k,$v) = each %$Irpg::Event::commands) {$commands{$k} = $v;}
+while (($k,$v) = each %$Irpg::Admin::commands) {$commands{$k} = $v;}
+while (($k,$v) = each %$Irpg::Users::commands) {$commands{$k} = $v;}
+undef $k;
+undef $v;
 
-while (my ($k,$v) (each %$Irpg::Quest::commands)) {$commands{$k} = $v;}
-while (my ($k,$v) (each %$Irpg::Fight::commands)) {$commands{$k} = $v;}
-while (my ($k,$v) (each %$Irpg::Event::commands)) {$commands{$k} = $v;}
-while (my ($k,$v) (each %$Irpg::Admin::commands)) {$commands{$k} = $v;}
-while (my ($k,$v) (each %$Irpg::Users::commands)) {$commands{$k} = $v;}
-
-$commands{pause}  = {ref => \&spause_mode, adm => 1, prv => 1, pub => 0}
-$commands{silent} = {ref => \&silent_mode, adm => 1, prv => 1, pub => 0}
-$commands{reloaddb} = {ref => \&reloaddb, adm => 1, prv => 1, pub => 0}
+$commands{pause}  = {ref => \&spause_mode, adm => 1, prv => 1, pub => 0};
+$commands{silent} = {ref => \&silent_mode, adm => 1, prv => 1, pub => 0};
+$commands{reloaddb} = {ref => \&reloaddb, adm => 1, prv => 1, pub => 0};
 
 1;
diff --git a/Irpg/Quest.pm b/Irpg/Quest.pm
index 5de113005d35552a77d8b7c34c5dd75d67c649d1..4ae7e1c7087d0a90ef750c41ebbb74b027ff5d92 100644
--- a/Irpg/Quest.pm
+++ b/Irpg/Quest.pm
@@ -260,7 +260,7 @@ sub quest_info {
 				"$quest{text}. Participants must first reach ".
 				"[$quest{p1}->[0],$quest{p1}->[1]], then ".
 				"[$quest{p2}->[0],$quest{p2}->[1]].".
-				($opts{mapurl}?" See $opts{mapurl} to monitor ".
+				($opts->{mapurl}?" See $opts->{mapurl} to monitor ".
 				"their journey's progress.":""),$source);
 	}
 
@@ -268,12 +268,7 @@ sub quest_info {
 
 
 our $commands = {
-	quest => {
-		ref => \&quest_info,
-		adm => 0;
-		prv => 1;
-		pub => 1;
-	}
-}
+	quest => {ref => \&quest_info, adm => 0, prv => 1, pub => 1}
+};
 
 1;
diff --git a/Irpg/Users.pm b/Irpg/Users.pm
index 25abf8a534331e4cb906baccbe52936baa604fa6..5aa354d700b357451a650899aaf517972156eed4 100644
--- a/Irpg/Users.pm
+++ b/Irpg/Users.pm
@@ -4,11 +4,11 @@ use strict;
 use warnings;
 use Irpg::Utils qw(:data :text);
 use Irpg::Irc qw(:interaction @queue);
-use Irpg::Main qw($pausemode $silentmode $primnick $lastreg);
-
 
 my $opts;
 my $rps;
+my $onchan;
+my ($primnick_ref, $lastreg_ref, $silentmode_ref, $pausemode_ref);
 =head1 FUNCTION init_hashes
 	This function sets the references to
 	options and players hashes.
@@ -16,7 +16,10 @@ my $rps;
 =item SCALAR (ref)	- reference to the options hash
 =item SCALAR (ref)	- reference to the players hash
 =cut
-sub init_hashes { ($opts, $rps) = @_; }
+sub init_hashes { 
+	($opts, $rps, $onchan, $$primnick_ref,
+	 $lastreg_ref, $silentmode_ref, $pausemode_ref) = @_;
+}
 
 sub register {
 	my ($usernick, $username, $source, @arg) = @_;
@@ -32,7 +35,7 @@ sub register {
 			privmsg("IE : REGISTER Poseidon MyPassword M God of the ".
 					"Sea",$usernick);
 		}
-		elsif ($pausemode) {
+		elsif ($$pausemode_ref) {
 			privmsg("Sorry, new accounts may not be registered ".
 					"while the bot is in pause mode; please wait ".
 					"a few minutes and try again.",$usernick);
@@ -43,11 +46,11 @@ sub register {
 					$usernick);
 		}
 		elsif (lc($arg[0]) eq lc($opts->{botnick}) ||
-			   lc($arg[0]) eq lc($primnick)) {
+			   lc($arg[0]) eq lc($$primnick_ref)) {
 			privmsg("Sorry, that character name cannot be ".
 					"registered.",$usernick);
 		}
-		elsif (!exists($onchan{$usernick})) {
+		elsif (!exists($onchan->{$usernick})) {
 			privmsg("Sorry, you're not in $opts->{botchan}.",
 					$usernick);
 		}
@@ -77,14 +80,14 @@ sub register {
 			privmsg("Sorry, character classes must be < 31 chars ".
 					"long.",$usernick);
 		}
-		elsif (time() == $lastreg) {
+		elsif (time() == $$lastreg_ref) {
 			privmsg("Wait 1 second and try again.",$usernick);                
 		}
 		else {
 			if ($opts->{voiceonlogin}) {
 				sts("MODE $opts->{botchan} +v :$usernick");
 			}
-			$lastreg = time();
+			$$lastreg_ref = time();
 			$rps->{$arg[0]}{next} = $opts->{rpbase};
 			$rps->{$arg[0]}{class} = "@arg[6..$#arg]";
 			$rps->{$arg[0]}{level} = 0;
@@ -161,7 +164,7 @@ sub login {
 			notice("Sorry, no such account name. Note that ".
 					"account names are case sensitive.",$usernick);
 		}
-		elsif (!exists $onchan{$opts->{botchan}}{$usernick}) {
+		elsif (!exists $onchan->{$opts->{botchan}}{$usernick}) {
 			notice("Sorry, you're not in $opts->{botchan}.",
 					$usernick);
 		}
@@ -199,7 +202,7 @@ sub logout {
 }
 
 sub status {
-	return unless ($opts->{statuscmd})
+	return unless ($opts->{statuscmd});
 	my ($usernick, $username, $source, @arg) = @_;
 	if (!defined($username)) {
 		privmsg("You are not logged in.", $usernick);
@@ -320,8 +323,9 @@ sub help {
 
 sub info {
 	my ($usernick, $username, $source, @arg) = @_;
+	my $info;
 	if (!ha($username)) {
-		$info = "IRPG bot v$version by ElTata, ".
+		$info = "IRPG bot by ElTata, ".
 				"based on jotun's initial work.".
 				"https://gennuso.iiens.net/irpg. On via server: ".
 				$opts->{servers}->[0].". Admins online: ".
@@ -332,21 +336,21 @@ sub info {
 	}
 	else {
 		my $queuedbytes = 0;
-		$queuedbytes += (length($_)+2) for @queue; # +2 = \r\n
+		$queuedbytes += (length($_)+2) for @Irpg::Irc::queue; # +2 = \r\n
 		$info = sprintf(
 			"%.2fkb sent, %.2fkb received in %s. %d IRPG users ".
 			"online of %d total users. PAUSE_MODE is %d, ".
 			"SILENT_MODE is %d. Outgoing queue is %d bytes ".
 			"in %d items. On via: %s. Admins online: %s.",
-			$outbytes/1024,
-			$inbytes/1024,
+			$Irpg::Irc::outbytes/1024,
+			$Irpg::Irc::inbytes/1024,
 			duration(time()-$^T),
 			scalar(grep { $rps->{$_}{online} } keys(%$rps)),
 			scalar(keys(%$rps)),
-			$pausemode,
-			$silentmode,
+			$$pausemode_ref,
+			$$silentmode_ref,
 			$queuedbytes,
-			scalar(@queue),
+			scalar(@Irpg::Irc::queue),
 			$opts->{servers}->[0],
 			join(", ",map { $rps->{$_}{nick} }
 					  grep { $rps->{$_}{isadmin} && $rps->{$_}{online} }
@@ -371,6 +375,6 @@ our $commands = {
 	removeme => {ref => \&rmplayer,	adm => 0, prv => 1, pub => 1},
 	help	 => {ref => \&help,		adm => 0, prv => 1, pub => 1},
 	info	 => {ref => \&info,		adm => 0, prv => 1, pub => 0}
-}
+};
 
 1;
diff --git a/Irpg/Utils.pm b/Irpg/Utils.pm
index 7499db5fd4194c10101cfd3c12e4c7e5b31cd4ed..bd7d010a2cd72ddcc9fba66e45129ef8d1070f18 100644
--- a/Irpg/Utils.pm
+++ b/Irpg/Utils.pm
@@ -261,7 +261,7 @@ sub loaddb { # load the players database
                 "fields (".scalar(@i).")",1);
         }
         if (!$sock) { # if not RELOADDB
-            if ($i[8]) { $prev_online->{$i[7]}=$i[0]; } # log back in
+            if ($i[8]) { $prev_online{$i[7]}=$i[0]; } # log back in
         }
         ($rps{$i[0]}{pass},
         $rps{$i[0]}{isadmin},
@@ -299,7 +299,7 @@ sub loaddb { # load the players database
     }
     close(RPS);
     debug("loaddb(): loaded ".scalar(keys(%rps))." accounts, ".
-          scalar(keys(%$prev_online))." previously online.");
+          scalar(keys(%prev_online))." previously online.");
 	return (\%rps, \%prev_online);
 }
 
diff --git a/irpg_bot.pl b/irpg_bot.pl
index 33095039fc3b00d7e27aaccc8a57063ce69fe736..1fb5b7f36ce45fc268e7bf85ece13ead3f41f303 100644
--- a/irpg_bot.pl
+++ b/irpg_bot.pl
@@ -138,6 +138,7 @@ debug("Config: read $_: ".Dumper($opts{$_})) for keys(%opts);
 my $rps = {}; # role-players
 my $prev_online = {}; # user@hosts online on restart, die
 my $auto_login = {}; # users to automatically log back on
+my $lasttime = 1; # last time that rpcheck() was run
 
 $rps = createdb(\%opts) unless -e $opts{dbfile};
 
@@ -152,7 +153,7 @@ CONNECT:
 
 irc_connect(\%opts);
 
-init_hashes(\%opts, $rps, $prev_online, $auto_login);
+Irpg::Main::init_pkg(\%opts, $rps, \$lasttime, $prev_online, $auto_login);
 
 #-----------------#
 #    MAIN LOOP    #
@@ -167,7 +168,7 @@ while (1) {
 		# we've logged in the users in %auto_login. so, we'll set those
 		# users' online flags to 1, rewrite db, and attempt to reconnect
 		# (if that's wanted of us)
-		$rps{$_}{online}=1 for keys(%$auto_login);
+		$rps->{$_}{online}=1 for keys(%$auto_login);
 		writedb(\%opts, $rps);
 		if ($opts{reconnect}) {
 			irc_clean(\%opts);
@@ -175,5 +176,5 @@ while (1) {
 		}
 		else { debug("Socket closed; disconnected.",1); }
 	}
-    if ((time()-$lasttime) >= $opts{self_clock}) { rpcheck(\%opts, $rps); }
+    if ((time()-$lasttime) >= $opts{self_clock}) { rpcheck(); }
 }