[misc] Added unit test and did some related minor improvements