added tons of comments for better understanding