fix inconsistency in variable names
reorganise and condense