Adapted to comments by @JohanDS