Completed code.
Tested it and it works on my laptop.