updating code with better comments