Slight rework, add in some ideas from code notes.