added hasData() and minor code clean