ultra-naive implementation, but it works