See commits for changes. I made sure to provide detailed comments :)