first part optimization bug fixed