Borrowed these two functions from Picard