Fix bunch of bugs.