Fix some bugs and add more functionality.