simplified, refactoring, error handling