lots of bugfixes and improve tests automation