Some refactoring, started .nds support