tons of refactoring of paths and small functions into this file.