Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java	(revision 28202)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java	(revision 28210)
@@ -128,5 +128,4 @@
 	protected static final String GET_USER_INFORMATION_SERVICE = "GetUserInformation";
 
-	protected static DerbyWrapper _derbyWrapper = null;
 	protected static boolean _derbyWrapperDoneForcedShutdown = false;
 
@@ -157,5 +156,4 @@
 
 			DerbyWrapper.shutdownDatabaseServer();
-			_derbyWrapper = null;
 			_derbyWrapperDoneForcedShutdown = true;
 		}
@@ -271,9 +269,9 @@
 		}
 
-		openDatabase();
+		DerbyWrapper derbyWrapper = openDatabase();
 
 		try
 		{
-			UserQueryResult userQueryResult = _derbyWrapper.findUser(username);
+			UserQueryResult userQueryResult = derbyWrapper.findUser(username);
 
 			Vector<UserTermInfo> terms = userQueryResult.getUserTerms();
@@ -282,5 +280,4 @@
 			{
 				GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_REQUESTED_USER_NOT_FOUND));
-				closeDatabase();
 				return result;
 			}
@@ -308,5 +305,5 @@
 		}
 
-		closeDatabase();
+		derbyWrapper.closeDatabase();
 
 		return result;
@@ -664,7 +661,9 @@
 			}
 
+			DerbyWrapper derbyWrapper = openDatabase();
 			String chpa_groups = retrieveDataForUser(user_name, "groups");
 			String chpa_comment = "password_changed_by_user";
-			String info = this._derbyWrapper.modifyUserInfo(user_name, hashPassword(newPassword), chpa_groups, null, chpa_comment, null);
+			String info = derbyWrapper.modifyUserInfo(user_name, hashPassword(newPassword), chpa_groups, null, chpa_comment, null);
+			derbyWrapper.closeDatabase();
 			if (info != "succeed")
 			{//see DerbyWrapper.modifyUserInfo
@@ -820,7 +819,7 @@
 	private void checkAdminUserExists()
 	{
-		openDatabase();
-
-		UserQueryResult userQueryResult = _derbyWrapper.findUser(null, null);
+		DerbyWrapper derbyWrapper = openDatabase();
+		UserQueryResult userQueryResult = derbyWrapper.findUser(null, null);
+		derbyWrapper.closeDatabase();
 
 		if (userQueryResult != null)
@@ -842,52 +841,38 @@
 			}
 		}
-
-		closeDatabase();
-	}
-
-	private boolean openDatabase()
-	{
-		if (_derbyWrapper == null)
-		{
-			// check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
-			String usersDB_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB";
-
-			_derbyWrapper = new DerbyWrapper(usersDB_dir);
-
-			File usersDB_file = new File(usersDB_dir);
-			if (!usersDB_file.exists())
-			{
-				String etc_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc";
-				File etc_file = new File(etc_dir);
-				if (!etc_file.exists())
-				{
-					boolean success = etc_file.mkdir();
-					if (!success)
-					{
-						logger.error("Couldn't create the etc dir under " + GlobalProperties.getGSDL3Home() + ".");
-						return false;
-					}
-				}
-				_derbyWrapper.createDatabase();
-			}
-		}
-
-		return true;
-	}
-
-	private void closeDatabase()
-	{
-		if (_derbyWrapper != null)
-		{
-			_derbyWrapper.closeDatabase();
-			_derbyWrapper = null;
-		}
+	}
+
+	private DerbyWrapper openDatabase()
+	{
+		// check the usersDb database, if it isn't existing, check the etc dir, create the etc dir if it isn't existing, then create the  user database and add a "admin" user
+		String usersDB_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB";
+
+		DerbyWrapper derbyWrapper = new DerbyWrapper(usersDB_dir);
+
+		File usersDB_file = new File(usersDB_dir);
+		if (!usersDB_file.exists())
+		{
+			String etc_dir = GlobalProperties.getGSDL3Home() + File.separatorChar + "etc";
+			File etc_file = new File(etc_dir);
+			if (!etc_file.exists())
+			{
+				boolean success = etc_file.mkdir();
+				if (!success)
+				{
+					logger.error("Couldn't create the etc dir under " + GlobalProperties.getGSDL3Home() + ".");
+					return null;
+				}
+			}
+			derbyWrapper.createDatabase();
+		}
+
+		return derbyWrapper;
 	}
 
 	private int addUserInformationToNode(String username, Element serviceNode)
 	{
-		openDatabase();
-
-		UserQueryResult userQueryResult = _derbyWrapper.findUser(username, null);
+		DerbyWrapper derbyWrapper = openDatabase();
+		UserQueryResult userQueryResult = derbyWrapper.findUser(username, null);
+		derbyWrapper.closeDatabase();
 
 		if (userQueryResult != null)
@@ -895,9 +880,7 @@
 			Element user_node = getUserNode(userQueryResult);
 			serviceNode.appendChild(user_node);
-			closeDatabase();
 			return NO_ERROR;
 		}
 
-		closeDatabase();
 		return ERROR_COULD_NOT_GET_USER_INFO;
 	}
@@ -910,15 +893,13 @@
 		}
 
-		openDatabase();
-
-		boolean success = _derbyWrapper.deleteUser(username);
+		DerbyWrapper derbyWrapper = openDatabase();
+		boolean success = derbyWrapper.deleteUser(username);
+		derbyWrapper.closeDatabase();
 
 		if (success)
 		{
-			closeDatabase();
 			return NO_ERROR;
 		}
 
-		closeDatabase();
 		return ERROR_REMOVING_USER;
 	}
@@ -926,14 +907,13 @@
 	private int addUser(String newUsername, String newPassword, String newGroups, String newStatus, String newComment, String newEmail)
 	{
-		openDatabase();
-
 		newGroups = newGroups.replaceAll(" ", "");
 
 		//Check if the user already exists
-		UserQueryResult userQueryResult = _derbyWrapper.findUser(newUsername, null);
+		DerbyWrapper derbyWrapper = openDatabase();
+		UserQueryResult userQueryResult = derbyWrapper.findUser(newUsername, null);
 
 		if (userQueryResult != null)
 		{
-			closeDatabase();
+			derbyWrapper.closeDatabase();
 			return ERROR_USER_ALREADY_EXISTS;
 		}
@@ -941,13 +921,13 @@
 		{
 			System.err.println("ADDING " + newUsername + " " + newPassword);
-			boolean success = _derbyWrapper.addUser(newUsername, newPassword, newGroups, newStatus, newComment, newEmail);
+			boolean success = derbyWrapper.addUser(newUsername, newPassword, newGroups, newStatus, newComment, newEmail);
+			derbyWrapper.closeDatabase();
+
 			if (!success)
 			{
-				closeDatabase();
 				return ERROR_ADDING_USER;
 			}
 		}
 
-		closeDatabase();
 		return NO_ERROR;
 	}
@@ -957,9 +937,8 @@
 		boolean check_status = false;
 
-		openDatabase();
-
+		DerbyWrapper derbyWrapper = openDatabase();
 		try
 		{
-			UserQueryResult result = _derbyWrapper.findUser(username);
+			UserQueryResult result = derbyWrapper.findUser(username);
 
 			if (result != null)
@@ -974,6 +953,6 @@
 			ex.printStackTrace();
 		}
-
-		closeDatabase();
+		derbyWrapper.closeDatabase();
+
 		return check_status;
 	}
@@ -987,5 +966,7 @@
 		try
 		{
-			UserQueryResult result = _derbyWrapper.findUser(username);
+			DerbyWrapper derbyWrapper = openDatabase();
+			UserQueryResult result = derbyWrapper.findUser(username);
+			derbyWrapper.closeDatabase();
 			Vector userInfo = result.users;
 
@@ -1024,5 +1005,4 @@
 		}
 
-		closeDatabase();
 		return data;
 	}
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/UserTracker.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/UserTracker.java	(revision 28202)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/UserTracker.java	(revision 28210)
@@ -90,5 +90,4 @@
 	protected synchronized Element processGetActivityOnPage(Element request)
 	{
-		System.err.println("CALLED");
 		Element result = GSXML.createBasicResponse(this.doc, GET_ACTIVITY_ON_PAGE);
 		try
@@ -98,5 +97,4 @@
 			if (paramList == null)
 			{
-				System.err.println("WHA?");
 				GSXML.addError(this.doc, result, "Request has no parameter list");
 				return result;
@@ -110,6 +108,4 @@
 			DerbyWrapper database = new DerbyWrapper(GlobalProperties.getGSDL3Home() + File.separatorChar + "etc" + File.separatorChar + "usersDB");
 			ArrayList<HashMap<String, String>> userActions = database.getMostRecentUserActions(site, collection, oid);
-
-			System.err.println(userActions.size());
 
 			Element userList = this.doc.createElement("userList");
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 28202)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java	(revision 28210)
@@ -197,5 +197,5 @@
 		try
 		{
-			String query = "SELECT username, action FROM usertracker WHERE site = '" + site + "' and collection = '" + collection + "' and oid = '" + oid + "' ORDER BY time";
+			String query = "SELECT username, action, time FROM usertracker WHERE site = '" + site + "' and collection = '" + collection + "' and oid = '" + oid + "' ORDER BY time";
 			Statement state = conn.createStatement();
 			ResultSet rs = state.executeQuery(query);
@@ -203,7 +203,14 @@
 
 			HashSet<String> usernamesSeen = new HashSet<String>();
-
 			while (rs.next())
 			{
+				String timeStr = rs.getString("time");
+				long time = Long.parseLong(timeStr);
+
+				if (System.currentTimeMillis() - time > 6000)
+				{
+					continue;
+				}
+
 				HashMap<String, String> action = new HashMap<String, String>();
 				if (!usernamesSeen.contains(rs.getString("username")))
@@ -217,4 +224,6 @@
 			}
 			state.close();
+
+			clearOldUserActions();
 		}
 		catch (Exception ex)
@@ -223,4 +232,19 @@
 		}
 		return actions;
+	}
+
+	public void clearOldUserActions()
+	{
+		try
+		{
+			Statement state = conn.createStatement();
+			state.execute("DELETE FROM usertracker WHERE (CAST (time AS BIGINT)) < " + (System.currentTimeMillis() - 20000));
+			conn.commit();
+			state.close();
+		}
+		catch (Exception ex)
+		{
+			ex.printStackTrace();
+		}
 	}
 
@@ -572,4 +596,5 @@
 		Statement state = conn.createStatement();
 		ResultSet rs = state.executeQuery(sql_find_user);
+		conn.commit();
 		while (rs.next())
 		{
@@ -583,9 +608,11 @@
 			users.add(user);
 		}
-		conn.commit();
-
+		state.close();
+
+		state = conn.createStatement();
 		for (HashMap<String, String> user : users)
 		{
 			ResultSet gs = state.executeQuery("SELECT role FROM " + ROLES + " WHERE username = '" + user.get("username") + "'");
+			conn.commit();
 
 			String group = "";
