Added code. Needs tests.