a lot of tuning and some bug fixes