Refactor code for checking basic class type