 app.post '/action/newCharacter',
 	mustBeAuthed,
 	setInstance('new_character'),
-	(request, response) ->
+	openTransaction,
+	(request, response, next) ->
 		nameIsValid = lib.validation.characterNameIsValid(request.body.character_name)
-		alreadyExists = lib.character.characterExists.sync(null, dbConnection, request.body.character_name)
+		alreadyExists = lib.character.characterExists.sync(null, request.uonline.tx, request.body.character_name)
 
 		if nameIsValid and not alreadyExists
 			charid = lib.character.createCharacter.sync(
 				null
-				dbConnection
+				request.uonline.tx
 				request.uonline.user.id
 				request.body.character_name
 				request.body.character_race
 				request.body.character_gender
 			)
-			response.redirect 303, '/character/'
+			request.uonline.characterCreated = true
 		else
 			options = request.uonline
 			options.error = true
 			options.invalidName = !nameIsValid
 			options.nameIsBusy = alreadyExists
 			options.character_name = request.body.character_name
-			response.render 'new_character', options
+			request.uonline.options = options
+			request.uonline.characterCreated = false
+		next()
+	,
+	commit,
+	(request, response) ->
+		if request.uonline.characterCreated
+			response.redirect 303, '/character/'
+		else
+			response.render 'new_character', request.uonline.options
 
 
 app.get '/game/',

app.get '/explode/', (request, response) ->
	throw new Error 'Emulated error.'

app.get '/explode_db/', (request, response) ->
	dbConnection.query.sync dbConnection, 'SELECT * FROM "Emulated DB error."'


app.get '/', (request, response) ->

			options.loginIsBusy = userExists
			options.user.username = request.body.username
			options.user.password = request.body.password
			request.uonline.options = options
			request.uonline.userCreated = false
		next()
	,
	commit,
	(request, response) ->
		if request.uonline.userCreated
			response.redirect 303, '/'
		else
			response.render 'register', request.uonline.options


app.get '/character/',
