TempDB now replaces already existing entries.
Added tests and applied comments.