Fixes bugs and code style.