Bunch of fine tuning and bug fixes