almost refactored attach/load