Added tests for list function and fixed bugs in it.