Refactoring & fix issues found by SensioLabsInsight