format code ; fix reference bug