Fix some errors and add debug to log