Converted all functions to use matrix-like operations. Significant speedup. If more is needed, may need to switch to BIDMach or Spark.