initial trim and restore search path

Seem to be working okay, added tests as well