significant filesystem code cleanup, left in old code in separate file for now