refactoring my debugging function