solution to #12, need a faster one though