Refactoring to simplify the code. Add function to animate the training of PLA. Fix a few bugs.