Fix bugs and add all functional