Rules import/export plus some code cleanup
@trivial changes as per review comments