Improve debugging output and add more function documentation