added error functions finally