fixed support for relative references; refactoring