REFACTOR Neural network thread