Improving efficiency of some slow code; timeout option added - closes #236
more speed improvements