Added decryption

and improved some code.