More code tidyup and comments