nuked current code, now will try with just loops for the sake of passing tests. need to vectorize later