further edits to debug
improved debug handling on function