Tidied formatting and added in missing loop starts