Imporove logging and add debug levels.