fix some bug's and add debug messages