fixing lots of bugs and adding qDebugs