Memory optimzation for constructPath

Changed multiple string operations to one final operation for 'd' in constructPath.