refactor: minor refactor and improvements, support empty inputs, add more test cases