refactoring and ways to handle invalid and used token