Rewrite as a real lib