refactor
refactor error handling