rebasing with proper commenting and docs