slight speedup
some cleanup
Make everything accept lists as input.