Moved code into functions
Added function to process ngrams in spark