Fix bugs and implement some new features