Fixed and cleaned up more code.

Still need to clean up encrypt and decrypt code.