add debug mode trigger
improve error logging