functions and debug