Added 'when' and a small set of tests associated with the function.