CS fixes detected by scrutinizer
added more tests