improved ej4.c