Restructured code to allow extra error tracking
Adding isAttached capability