Changed the code to make it, hopefully, easier to understand.