rewrite using tests first