Bugfixes and a new function