Waqas/for545 user last thread not remembered

Note: I will add the tests in the subsequent commit
Don't copy/paste. Factor out a function instead.