Refactor API and implement/test ls command