refactored code; fixed dat file path alloc bug