Bugfixes and some preliminary security work