I think this works. Needs real-life testing =) Fixes #6 for now.