splitting into multiple files
moved flatten for compatibility
with-debug-funs finished