Finish static analysis and fix bugs