Optimised the code to run perfectly on Console window.