Split a function for ease of unit testing. Added unit tests in test_task1.py