optimized a function in eco.c