Reference handling

Reference handling added and documents moved around