Made some changes and started working on Issue #2

But the function is still not working correctly and needs to be
revisited.