some fixes and code cleaning