bugs fixed in above functions