Security rewritten, still some bugs somewhere