Improved codequality, bugfixes