some improvements and more structure