Bugfixes and safer code