code detection and revision detection
final version before use. minor clean ups