Reorganized the code to segregate the platform dependent and independent parts of the code