Add debugging with debug and debugHard
extract functions from Internal module to fix #3