Updated code of metrics with listing functions and error handling