Fixed everything. Now it works. Also tried to split code into different files.