Added validity checks to time sensitive code.