Refactored code

added machine learning and data writing function files. The machine
learning will also include the training of the system.