Added refinements to tidy up code