Made two functions smarter