with some minor fixes