Tried a more versatile approach, still buggy.