this is heavily reffed and partially traced so really most of the credit for this goes to kiyohiko a