code improvements, tests