[bug 1050565] Added tests and fixed a few errors.