Fix referencing and remove unused references