Restructured and refactored code. Added more print calls.