First try at handling target magic
Fix some problems with the previous commit