Refactor contents of mlpipe.py, add comments.