Fixed optimization bug