more idiomatic error handling and type checking

use Error objects, err variable name and return after calling back with an error