fix bugs and implement basic functions