[test] Adding tests
[minor] Cleanup the code.