Addressed comments. I left initalizing of  A, IA and JA to empty lists, as I think they serve as good documentation.