Fix bunch of bugs