fix bugs in optional implementation