Massive code review

happy reviewing...

@acus and @philip-crunch