revised code functioning
revised the code to implement OOP