Some edits and attempts at perf improvement.