Improve implementation
Add comments to explain implementation in detail