reformat
abstract handler functions and handle errors in a single place