Added checks for invalid numbers