Another attempt at optimization