Fix undefined data error and fix js style according to jshint