made python3 compatible
added test cases