Non recursive, but not correct solution