Refactoring almost complete. Forward and backward are sometimes wrong.