move error handling to separate module