added optimization stuff