added all the code, ver. 1