Several Bugfixes and added some Tests