optimize & error handle.