Fixed some bugs, it is working fine now.