Changed array based implemenatation to ArrayList