Implement some function and fix bugs