rewritten in cc

rewritten in gnu++0x, and solved capture problem.