closer to @holgersindbaek's code