I have added my own functions for debug and adapted it to what we want to do