Made code more generic: List instead of ArrayList