add debug code, and fix two bugs in APPLY
removed all unnecessary files