typedef added tested (with error handling)