improved design by @sicher