Refactored code & fixed warnings