code cleaning + fix errors