Converted attach.c into a library