Added missing imports and modifed to use ArrayList more consitently.