intermediate commit. rows and columns might have been interchanged. too much duplicate code, long main function , looks like the shittiest code that can ever be written..:(