added a Result type for functional error handling. Still has errors.