some refactor on solver and optimizer