made several minor fixes as pointed out by Andrey