Improved security and fixed an error in the update function