Third try. Fix some error because I have to put some variables on global. But still does not work