apply the comments about the code made by @fw42