add reference and some bugfixes