Fixing up bugs in decrypt function