Bugfixes and some new functions