Fixing some bugs and adding some new features