added debug codes when error occurs