code clean and bugfixes