add conditionals to check null pointers in attach