diff --git a/engine/client/cl_input.c b/engine/client/cl_input.c
index 5a7168446..6f8827cd9 100644
--- a/engine/client/cl_input.c
+++ b/engine/client/cl_input.c
@@ -623,12 +623,12 @@ void CL_ClampPitch (int pnum)
 	}
 	if (pv->pmovetype == PM_6DOF)
 	{
-		vec3_t impact;
-		vec3_t norm;
+//		vec3_t impact;
+//		vec3_t norm;
 		float mat2[16];
-		vec3_t cross;
+//		vec3_t cross;
 		vec3_t view[4];
-		float dot;
+//		float dot;
 		AngleVectors(pv->viewangles, view[0], view[1], view[2]);
 		Matrix4x4_RM_FromVectors(mat, view[0], view[1], view[2], vec3_origin);
 
diff --git a/engine/common/pmovetst.c b/engine/common/pmovetst.c
index 9a1922672..cec891223 100644
--- a/engine/common/pmovetst.c
+++ b/engine/common/pmovetst.c
@@ -263,7 +263,7 @@ static qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t en
 //a portal is flush with a world surface behind it.
 //this causes problems. namely that we can't pass through the portal plane if the bsp behind it prevents out origin from getting through.
 //so if the trace was clipped and ended infront of the portal, continue the trace to the edges of the portal cutout instead.
-void PM_PortalCSG(physent_t *portal, float trminz, float trmaxz, vec3_t start, vec3_t end, trace_t *trace)
+void PM_PortalCSG(physent_t *portal, float *trmin, float *trmax, vec3_t start, vec3_t end, trace_t *trace)
 {
 	vec4_t planes[6];	//far, near, right, left, up, down
 	int plane;
@@ -286,19 +286,26 @@ void PM_PortalCSG(physent_t *portal, float trminz, float trmaxz, vec3_t start, v
 	VectorNegate(planes[3], planes[2]);
 	VectorNegate(planes[5], planes[4]);
 
-	trminz = fabs(trminz);
 	portalradius/=2;
-	planes[0][3] = DotProduct(portal->origin, planes[0]) - (trminz+fabs(trmaxz)+16);
-	planes[1][3] = DotProduct(portal->origin, planes[1]) - (64.0/32);	//an epsilon beyond the portal
-	planes[2][3] = DotProduct(portal->origin, planes[2]) - portalradius+trminz;
-	planes[3][3] = DotProduct(portal->origin, planes[3]) - portalradius+trminz;
-	planes[4][3] = DotProduct(portal->origin, planes[4]) - portalradius+trminz;
-	planes[5][3] = DotProduct(portal->origin, planes[5]) - portalradius+trminz;
+	planes[0][3] = DotProduct(portal->origin, planes[0]) - (1.1/32);
+	planes[1][3] = DotProduct(portal->origin, planes[1]) - (1.1/32);	//an epsilon beyond the portal
+	planes[2][3] = DotProduct(portal->origin, planes[2]) - portalradius;
+	planes[3][3] = DotProduct(portal->origin, planes[3]) - portalradius;
+	planes[4][3] = DotProduct(portal->origin, planes[4]) - portalradius;
+	planes[5][3] = DotProduct(portal->origin, planes[5]) - portalradius;
 
 	//if we're actually inside the csg region
 	for (plane = 0; plane < 6; plane++)
 	{
+		vec3_t nearest;
 		float d = DotProduct(worldpos, planes[plane]);
+		int k;
+		for (k = 0; k < 3; k++)
+			nearest[k] = (planes[plane][k]>=0)?trmax[k]:trmin[k];
+		if (!plane)	//front plane gets further away with side
+			planes[plane][3] -= DotProduct(nearest, planes[plane]);
+		else if (plane>1)	//side planes get nearer with size
+			planes[plane][3] += DotProduct(nearest, planes[plane]);
 		if (d - planes[plane][3] >= 0)
 			continue;	//endpos is inside
 		else
@@ -370,7 +377,7 @@ qboolean PM_TestPlayerPosition (vec3_t pos)
 				{
 					pe = &pmove.physents[j];
 					if (pe->isportal)
-						PM_PortalCSG(pe, pmove.player_mins[2], pmove.player_maxs[2], pos, pos, &trace);
+						PM_PortalCSG(pe, pmove.player_mins, pmove.player_maxs, pos, pos, &trace);
 				}
 				if (trace.allsolid)
 					return false;
@@ -434,7 +441,7 @@ trace_t PM_PlayerTrace (vec3_t start, vec3_t end, unsigned int solidmask)
 		else if (pe->isportal)
 		{
 			//make sure we don't hit the world if we're inside the portal
-			PM_PortalCSG(pe, pmove.player_mins[2], pmove.player_maxs[2], start, end, &total);
+			PM_PortalCSG(pe, pmove.player_mins, pmove.player_maxs, start, end, &total);
 
 			// trace a line through the apropriate clipping hull
 			if (!PM_TransformedHullCheck (pe->model, start, end, vec3_origin, vec3_origin, &trace, pe->origin, pe->angles))
@@ -452,7 +459,7 @@ trace_t PM_PlayerTrace (vec3_t start, vec3_t end, unsigned int solidmask)
 				{
 					pe = &pmove.physents[j];
 					if (pe->isportal)
-						PM_PortalCSG(pe, pmove.player_mins[2], pmove.player_maxs[2], start, end, &trace);
+						PM_PortalCSG(pe, pmove.player_mins, pmove.player_maxs, start, end, &trace);
 				}
 				pe = &pmove.physents[i];
 			}
diff --git a/engine/gl/gl_rmain.c b/engine/gl/gl_rmain.c
index 96dc74002..5f976c432 100644
--- a/engine/gl/gl_rmain.c
+++ b/engine/gl/gl_rmain.c
@@ -843,7 +843,7 @@ void GLR_DrawPortal(batch_t *batch, batch_t **blist, batch_t *depthmasklist[2],
 	}
 	else
 	{
-		vec3_t point, vel;
+		vec3_t point;
 		VectorCopy(plane.normal, oplane.normal);
 		//rotate the surface normal around its entity's matrix
 		plane.normal[0] = oplane.normal[0]*batch->ent->axis[0][0] + oplane.normal[1]*batch->ent->axis[1][0] + oplane.normal[2]*batch->ent->axis[2][0];
diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c
index 4a6ca947c..e505de1dd 100644
--- a/engine/server/pr_cmds.c
+++ b/engine/server/pr_cmds.c
@@ -4357,9 +4357,10 @@ extern sizebuf_t csqcmsgbuffer;
 void QCBUILTIN PF_WriteByte (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals)
 {
 	int dest = G_FLOAT(OFS_PARM0);
+	qbyte val = (qbyte)G_FLOAT(OFS_PARM1);
 	if (dest == MSG_CSQC)
 	{	//csqc buffers are always written.
-		MSG_WriteByte(&csqcmsgbuffer, G_FLOAT(OFS_PARM1));
+		MSG_WriteByte(&csqcmsgbuffer, val);
 		return;
 	}
 
@@ -4373,13 +4374,13 @@ void QCBUILTIN PF_WriteByte (pubprogfuncs_t *prinst, struct globalvars_s *pr_glo
 
 	if (progstype == PROG_NQ || progstype == PROG_H2)
 	{
-		NPP_NQWriteByte(dest, (qbyte)G_FLOAT(OFS_PARM1));
+		NPP_NQWriteByte(dest, val);
 		return;
 	}
 #ifdef NQPROT
 	else
 	{
-		NPP_QWWriteByte(dest, (qbyte)G_FLOAT(OFS_PARM1));
+		NPP_QWWriteByte(dest, val);
 		return;
 	}
 #else
@@ -4389,19 +4390,20 @@ void QCBUILTIN PF_WriteByte (pubprogfuncs_t *prinst, struct globalvars_s *pr_glo
 		if (!cl)
 			return;
 		ClientReliableCheckBlock(cl, 1);
-		ClientReliableWrite_Byte(cl, G_FLOAT(OFS_PARM1));
+		ClientReliableWrite_Byte(cl, val);
 	}
 	else
-		MSG_WriteByte (QWWriteDest(G_FLOAT(OFS_PARM0)), G_FLOAT(OFS_PARM1));
+		MSG_WriteByte (QWWriteDest(dest), val);
 #endif
 }
 
 void QCBUILTIN PF_WriteChar (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals)
 {
 	int dest = G_FLOAT(OFS_PARM0);
+	char val = (char)G_FLOAT(OFS_PARM1);
 	if (dest == MSG_CSQC)
 	{	//csqc buffers are always written.
-		MSG_WriteChar(&csqcmsgbuffer, G_FLOAT(OFS_PARM1));
+		MSG_WriteChar(&csqcmsgbuffer, val);
 		return;
 	}
 
@@ -4414,13 +4416,13 @@ void QCBUILTIN PF_WriteChar (pubprogfuncs_t *prinst, struct globalvars_s *pr_glo
 
 	if (progstype == PROG_NQ || progstype == PROG_H2)
 	{
-		NPP_NQWriteChar(dest, (char)G_FLOAT(OFS_PARM1));
+		NPP_NQWriteChar(dest, val);
 		return;
 	}
 #ifdef NQPROT
 	else
 	{
-		NPP_QWWriteChar(dest, (char)G_FLOAT(OFS_PARM1));
+		NPP_QWWriteChar(dest, val);
 		return;
 	}
 #else
@@ -4430,10 +4432,10 @@ void QCBUILTIN PF_WriteChar (pubprogfuncs_t *prinst, struct globalvars_s *pr_glo
 		if (!cl)
 			return;
 		ClientReliableCheckBlock(cl, 1);
-		ClientReliableWrite_Char(cl, G_FLOAT(OFS_PARM1));
+		ClientReliableWrite_Char(cl, val);
 	}
 	else
-		MSG_WriteChar (QWWriteDest(dest), G_FLOAT(OFS_PARM1));
+		MSG_WriteChar (QWWriteDest(dest), val);
 #endif
 }
 
diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c
index 164ff3cc5..483851802 100644
--- a/engine/server/sv_main.c
+++ b/engine/server/sv_main.c
@@ -5899,7 +5899,7 @@ void SV_ExecInitialConfigs(char *defaultexec)
 	if (COM_FileSize("server.cfg") != -1)
 		Cbuf_InsertText ("exec server.cfg\nexec ftesrv.cfg\n", RESTRICT_LOCAL, false);
 	else
-		Cbuf_InsertText ("cl_warncmd 0\nexec quake.rc\nexec ftesrv.cfg\ncl_warncmd 1\n", RESTRICT_LOCAL, false);
+		Cbuf_InsertText ("cl_warncmd 0\nexec quake.rc\ncl_warncmd 1\nexec ftesrv.cfg\n", RESTRICT_LOCAL, false);
 
 // process command line arguments
 	Cbuf_Execute ();