code integrated from samanvita and shahib without refactoring