Completed overhaul of core functionality.

Now using element traversal rather than string replacement.