final changes and some bugs fixed