added verbose switch. Fix some bugs