fix bugs and finish basic function