code refactored and added explanation in label