fixed bugs and add new functional