Fixed looping over list instead of map; added tests