refactored and fixed code inspections

please review it and ship it to your project