Bug fixing and improvements