add record option
vectorize for vastly improved performance
refactor into more separate functions
profiling