Fixing some bugs here and there.
Added a simple regression for security critical functions.