this works sortof but not thoroughly tested