Bugfixes, common refactoring, add safely methods