added opt dir, fixed bug