fix
add error handling
refactoring