(I know you just copied an existing code, but this is a good excuse to make it better)