Revert "close file on error"

This reverts commit 8f8b08552ac2316eadeb38d98b3e5855f0c4f148.
Revert "code clean up"

This reverts commit 92c73d86ecc8e7919b6f44fc954ab7c72b3a1ce1.
revert 6a527e4
Revert "optimized appkey reading"

This reverts commit 2625e74a5687034ddfffa53f5dafcb40a9b7c49b.
revert 264e60c