Changed while to if statements.

We don't need while loops as each viable occurance will be logm apart.

Also finally removed naive implementation.