@cryptoctopus,
You did it well, it works perfectly! Now the question is you can't assure you are 100% readable this code and you understood it 100%.
Don't worry, you know with experience you will read it well. We all are not 100% accurate, it takes time to make that happen! Therefore, don't worry you made a good short program and it works perfect! Congratz friend!
Cheers~
Congratz