Simplify some code a bit

The nested array feature is handy.
Use REPLACE instead of INSERT IGNORE for subs

If you changed the capitalization, let the new version take.