speed ups

from profiling, line 63 is veeery slow, lapply is faster than sapply.
Need to think about a sensible vectorisation speed up.
Lines 68-70 also slow.