updated with better comments