Address bluong's concerns, and also add more unit tests