finish optimization stuff