adding heap optimization