optim and bugfix