added two functions for error calculation