upgraded to takashi's version