a bit of refactoring & added error when there's no name match