tidied text
added summary, code formatted and minimally cleaned
final draft version