It was broken for some reason.....

debug option
Cleaning stuff up

Added some error handling where it should be, set debug to false,
removed commented code.
Comments, cleanup etc