Major refactoring of main gash module.