fixed potential bug, added option