Restructuring and Clean Up. Introduced Error Handling.