swaps some variables, some other fixes, mid-debugging