Got rid of recursive solution + fixing minor bugs