refactored code to resolve all warnings