Cleaned up and generalized to work with relative and absolute paths