added debugging codes to help with debug and trace