some improvements and cleanup