Removed the test code for empty lists and used exceptions instead.