Refactored the code. Imported the external libraries.