Working code
Commented, final code