Basically, I removed the data declarations (TABLES included) because you are using it just in this piece of code, I renamed the variables just for my personal taste and changed the CHECK because I want to remove my bad habit of use it (it will lead to errors if you change your code in the far future and don't notice it).