Fixing bugs and some improvements.