complete rewrite

works with firefox, but it's leaking processes