Joined highlevelapi and optimizer, moved tests around accordingly
Replaced isinstance() calls with equality tests where possible
utils: replace_fields() returns back the original node if there is nothing to replace
TODO: these items have been finished