complete rewrite for v0.3