fix incorrect use of open function
a little optimize whc code