code style and some architecture improvements