Big refactoring & debug

ok