Add timeout and exception management for magnets