Added checks for encoding