bug fixies + some cleaning