Added smart path detection so that it can be called from anywhere without breaking