BL added, rewrite some code