SAM - platform - tidy - rearrange code, clarify comments