Security improvements, layout tweaks and additions, moderate refactoring