Improved code quality and added an exception for missing unit