Refactored, fixed warnings