Added unit test and fixed for Python 3