added some type annotation and minor changes