major refactoring of fat.c