Refactoring checkTyping function