optimize & fix underlying bug