ported to py3 and added unittest