Added some apply functions

Added 2 or 3 apply functions to try and improve speed of code. Added one
llply function from plyr library so that I could include code for
something to run in parallel.