Added function, bugfixes