Made a few changes + debug messages.