made matrices resizable and modularized the code