copied some of yours
fixed merge
using name instead of id