Refactored code; Fixed some of the warnings