Refactoring for perceptron algorithm